Skip to content

Improve error handling for login connection issues#143

Closed
feichashao wants to merge 2 commits intoopenshift:mainfrom
feichashao:auth_message
Closed

Improve error handling for login connection issues#143
feichashao wants to merge 2 commits intoopenshift:mainfrom
feichashao:auth_message

Conversation

@feichashao
Copy link
Contributor

What type of PR is this?

Bug

What this PR does / Why we need it?

If login returns an authentication issues (4xx), and we don't have a proxy set, the current logic will show the error cannot connect to backplane API URL, check if you need to use a proxy/VPN to access backplane.

The PR changes the error handling to only print such error when the error returned from doLogin is exactly a network issue. And if the error returned from doLogin is a network issue, we don't need to test the connection again, thus removing the bpConfig.CheckAPIConnection check.

Which Jira/Github issue(s) does this PR fix?

https://issues.redhat.com/browse/OSD-17374

Resolves #

Special notes for your reviewer

Tested locally.
For connection issue, it will show

./ocm-backplane login xxxxx
ERRO[0006] cannot connect to backplane API URL, check if you need to use a proxy/VPN to access backplane: unable to connect to backplane api: Post "https://localhost:8001/backplane/login/xxxx/": dial tcp [::1]:8001: connect: connection refused 

For authentication issue, it will show

./ocm-backplane login xxxxx
ERRO[0008] can't login to cluster: error from backplane: 
 Status Code: 403
 Message: no backplane role found for user yyyyy /FakeResource err/BackplaneOsdCeeResource false / 

Pre-checks (if applicable)

  • Ran unit tests locally
  • Validated the changes in a cluster
  • Included documentation changes with PR

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 7, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: feichashao

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 7, 2023
@feichashao
Copy link
Contributor Author

/retest-required

return fmt.Errorf("cluster %s is hibernating, login failed", clusterKey)
}
// Check API connection with configured proxy
err = bpConfig.CheckAPIConnection()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to remove bpConfig.CheckAPIConnection(), which is ping to api end-point and validates the connection?

connectionOk, err := config.testHttpRequestToBackplaneAPI()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tired changing the logic to only perform CheckAPIConnection only when the error returned is errLoginConnection but fails the test cases.

if errors.Is(err, errLoginConnection) {
			connectionErr := bpConfig.CheckAPIConnection()
			if connectionErr != nil {
				return fmt.Errorf("cannot connect to backplane API URL, check if you need to use a proxy/VPN to access backplane: %v", connectionErr)
			}
		}

Test result:

• Failure [1.378 seconds]
Login command
/Users/feichashao/git/github/backplane-cli/cmd/ocm-backplane/login/login_test.go:28
  check cluster login
  /Users/feichashao/git/github/backplane-cli/cmd/ocm-backplane/login/login_test.go:187
    should fail when BP API timeouts [It]
    /Users/feichashao/git/github/backplane-cli/cmd/ocm-backplane/login/login_test.go:294

    Expected
        <string>: can't login to cluster: unable to connect to backplane api: dial tcp i/o timeout
    to contain substring
        <string>: cannot connect to backplane API URL

while I was trying to tweak the test case, I think we can instead skip testing the api connectivity as the error message from doLogin has already did a "test" on the apiserver, we can expose the actual network error + a hint about proxy/vpn to make the error logic simpler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this PR fixed the error overwriting issue.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 11, 2023

@feichashao: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/coverage e2dc46e link true /test coverage
ci/prow/test e2dc46e link true /test test

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 12, 2023
@openshift-merge-robot
Copy link
Contributor

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@feichashao
Copy link
Contributor Author

Closing this as #151 can solve this problem.

@feichashao feichashao closed this Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants